﻿using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using System.Linq;

namespace LogForParameter.Api
{
    /// <summary>
    /// 定义swaggerheader参数;
    /// </summary>
    public class ShowSwaggerHeader : IOperationFilter
    {
        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            if (operation.Parameters == null)
                operation.Parameters = new List<OpenApiParameter>();
            //if (context.ApiDescription.GroupName.Equals("FileSystem"))
            //{

            //}
            //var attrs = context.ApiDescription.ActionDescriptor.AttributeRouteInfo;
            // 如果 Attribute 是我们自定义的验证过滤器
            operation.Parameters.Add(new OpenApiParameter()
            {
                Name = "HospitalId",
                In = ParameterLocation.Header,
                Style = ParameterStyle.Simple,
                Required = false,
                Description = "院区标识",
            });
            operation.Parameters.Add(new OpenApiParameter()
            {
                Name = "departmentId",
                In = ParameterLocation.Header,
                Style = ParameterStyle.Simple,
                Required = false,
                Description = "部门标识",
            });
            operation.Parameters.Add(new OpenApiParameter()
            {
                Name = "userId",
                In = ParameterLocation.Header,
                Style = ParameterStyle.Simple,
                Required = false,
                Description = "用户标识",
            });
            operation.Parameters.Add(new OpenApiParameter()
            {
                Name = "password",
                In = ParameterLocation.Header,
                Style = ParameterStyle.Simple,
                Required = false,
                Description = "密码"
            });
            operation.Parameters.Add(new OpenApiParameter()
            {
                Name = "role",
                In = ParameterLocation.Header,
                Style = ParameterStyle.Simple,
                Required = false,
                Description = "角色",
            });

        }
    }
}
